﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities.Presentation.Model;
using System.Activities;
using System.Windows.Data;
using System.Windows;

namespace Vision.VisionWorkshop.Common
{
	public class ModelPropertyValueConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			ModelItem mi = value as ModelItem;

			if (null != mi)
			{
				// in order to generate a child node in the treeview
				// we need to return a collection, so fix up a few types of interest
				if (mi.ItemType.Equals(typeof(string)))
					return new List<object> { mi.GetCurrentValue() };
				
				if (mi.ItemType.IsSubclassOf(typeof(Activity)) || mi.ItemType.IsSubclassOf(typeof(ActivityDelegate)))
					return new List<object> { mi };

				//Telerik.Windows.Controls.RadTreeViewItem tvItem = new Telerik.Windows.Controls.RadTreeViewItem();
				//tvItem.Header = new Binding() { Source = mi, Path = new PropertyPath("Name"), Mode=BindingMode.TwoWay };
				//tvItem.DataContext = mi;

				//return tvItem;

				return mi;
			}
			else
			{
				return value;
			}

		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
